<style lang="scss" scoped>
    .teach-index,.layout{
        width:100vw;
        height: 100vh;
    }
    .layout{
        background:url('~@/assets/bg.jpg') no-repeat;
        background-size: cover;
    }
    .logo{
        font-size: 16px;
        line-height: 38px;
        img{
            width: 38px;
            height: 38px;
        }
    }
    .sider{
        line-height: 46px;
        background-color:rgba($color: #000000, $alpha: .85); 
        .active{
            background: $primary-color;
        }
    }
    .header{
        width: calc(100% - 200px);
        height: $header-height;
        line-height: $header-height;
        background: rgba($color: #000000, $alpha: .8);;
        position: fixed;
        padding:0 0 0 20px;
        .drag{
            -webkit-user-select: none;
            -webkit-app-region: drag;
            width: calc(100% - 84px);
        }
        .icon{
            width: 42px;
            line-height: $header-height;
            z-index: 9999999;
            i{
                color: #ccc;
            }
        }
    }
    .container{
        border-radius: 3px;
        min-height: calc(100vh - 60px);
        background-color: rgba($color: #000000, $alpha: .85);
    }
</style>
<style lang="scss">
    .teach-index .ivu-layout{
        background-color:transparent;
    }
</style>
<template>
<div class="teach-index">
    <Layout class="layout">
        <Sider :collapsible="false" :width="200" class="sider p-1">
            <div class="logo d-flex color-fff">
                <img src="~@/assets/logo.png" class="mr-1">
                <span>陆军军事交通学院</span>
            </div>
            <ul class="sider-menu color-fff text-center line-height-50 mt-3">
                <li class="border-radius pointer" @click="active_menu=index" :class="index===active_menu?'active':''" v-for="(val,index) in menu" :key="index">
                    <router-link v-if="val.link!=='logout'" :to="val.link" class="color-fff d-block">
                        <img :src="require('@/assets/sider-menu_'+val.link+'.png')" alt="">
                        {{val.title}}
                    </router-link>
                    <div v-else @click="logout">
                        <img src="@/assets/sider-menu_logout.png" alt="">
                        {{val.title}}
                    </div>
                </li>

            </ul>
        </Sider>
        <Layout>
            <Header class="header d-flex between">
                <div class="icon"><Icon type="md-return-left" class="pointer" size="20" v-if="is_show_back" @click="$router.back()"/></div>
                <div class="drag"></div>
                <div class="icon"><Icon type="md-close" class="pointer" @click="close"/></div>
            </Header>
            <Content class="p-1 mt-4" v-cloak>
                <div class="container p-1">
                    <router-view/>
                </div>
            </Content>
        </Layout>
    </Layout>
</div>
</template>
<script>
    import {class_list} from "@/common/tapi"
    import {mutations} from '@/store'
    export default {
        data(){
            return {
                is_show_back:false,
                active_menu:0,
                menu:[
                    {
                        title:'个人中心',
                        link:'center'
                    },
                    {
                        title:'班级管理',
                        link:'class'
                    },
                    {
                        title:'教师管理',
                        link:'teacher'
                    },
                    {
                        title:'我的课堂',
                        link:'my_lesson'
                    },
                    {
                        title:'创建课堂',
                        link:'create_lesson'
                    },
                    {
                        title:'答疑解惑',
                        link:'questions_list'
                    },
                    {
                        title:'退出登录',
                        link:'logout'
                    }
                ]
            }
        },
        methods:{
            set_var:mutations.set_var,
            logout(){
                this.$Modal.confirm({
                    title: '退出',
                    content: '退出当前账号吗',
                    onOk: () => {
                        localStorage.clear()
                        this.$router.push({path:'/'})
                    },
                });
                
            },
            close(){
                this.$Modal.confirm({
                    title: '关闭',
                    content: '确认关闭吗？',
                    onOk: () => {
                        this.$ipcRenderer.send('close')
                    },
                });
            }
        },
        watch:{
            '$route.name':{
                handler:function(){
                    const root=[]
                    this.menu.forEach((el,index)=>{
                        if(this.$route.name===el.link)
                            this.active_menu=index
                        if(el.link)
                            root.push(el.link)
                    })
                    this.is_show_back=!root.includes(this.$route.name)
                },
                immediate: true
            }
        },
    
        created(){
            const user=JSON.parse(localStorage.getItem('userinfo'))
            if(user.name!=='admin')
                this.menu.splice(2,1)
            class_list({list_rows:999999,page:1})
            .then(res=>{
                if(res){
                    this.set_var('classList',res.data.list)
                }
            })

        }
    }
</script>